﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace WebUITestDemo
{
    [TestClass]
    public class WebUITest
    {
        protected IWebDriver Driver;


        [TestInitialize]
        public void Init()
        {
            Driver = new ChromeDriver();
        }


        [TestCleanup]
        public void Clean()
        {
            Driver.Quit();
        }


        [TestMethod]
        public void TestMethod1()
        {
            Driver.Url = "http://www.vip56.cn";
            var linker = Driver.FindElement(By.LinkText("关于我们"));
            linker.Click();

            Assert.AreEqual( "关于我们",Driver .Title );
        }


        /* public void LoginInTest()
         {
             Driver.Url = "http://passport.cnblogs.com/user/signin";
             var userNameFieled = Driver.FindElement(By.Id("input1"));
             var passwordFieled = Driver.FindElement(By.Id("input2"));
             var submitBtn = Driver.FindElement(By.Id("signin"));

             userNameFieled.SendKeys("cnblogs");
             passwordFieled.SendKeys("sino5802486");

             submitBtn.Click();

             WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(5));
             wait.Until(ExpectedConditions.TextToBePresentInElementLocated(By.Id("tip_btn"), "用户名或密码错误\r\n\r\n联系 contact@cnblogs.com"));

             var errorInfoShow = Driver.FindElement(By.Id("tip_btn"));
             Assert.AreEqual(errorInfoShow.Text, "用户名或密码错误\r\n\r\n联系 contact@cnblogs.com");
         }*/


        [TestMethod]
        public void LoginInByPageObjectTest()
        {
            Driver.Url = "http://passport.cnblogs.com/user/signin";
            LoginPage page = new LoginPage(Driver);
            page.Login("cnblogs", "sino5802486");

            Assert.AreEqual(page.Tip, "用户名或密码错误\r\n\r\n联系 contact@cnblogs.com");
            
        }
    }
}
